/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.runtime.component
{
	
	import com.edi.proxy.component.EPOParam;
	import com.edi.proxy.component.HttpProxy;
	import com.edi.proxy.component.HttpProxyResult;
	import com.edi.proxy.component.SPOParam;
	import com.edi.runtime.Event.*;
	import com.edi.runtime.control.CheckBoxColumn;
	import com.edi.runtime.control.IndexLabelItemRender;
	import com.edi.utils.BOPObjectUtils;
	import com.edi.utils.BOPStringUtils;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.net.FileReference;
	import flash.net.URLRequest;
	import flash.net.registerClassAlias;
	import flash.utils.ByteArray;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;
	
	import mx.collections.ArrayCollection;
	import mx.collections.XMLListCollection;
	import mx.containers.Box;
	import mx.containers.HBox;
	import mx.containers.VBox;
	import mx.controls.Alert;
	import mx.controls.Button;
	import mx.controls.ComboBox;
	import mx.controls.DataGrid;
	import mx.controls.Label;
	import mx.controls.dataGridClasses.DataGridColumn;
	import mx.controls.listClasses.BaseListData;
	import mx.controls.listClasses.IListItemRenderer;
	import mx.core.ClassFactory;
	import mx.core.IFactory;
	import mx.core.IFlexModuleFactory;
	import mx.events.DataGridEvent;
	import mx.events.DragEvent;
	import mx.events.DropdownEvent;
	import mx.events.ListEvent;
	import mx.events.ScrollEvent;
	import mx.formatters.NumberFormatter;
	/**
	 * 表格控件
	 * @author HW
	 * 
	 */
	public class EDIDataGrid extends VBox implements IEDIDataLoad
	{
		private var _dataSourceName:String;
		//build by hw add colorDataGrid
		private var entry:BOPDatagrid=new BOPDatagrid();
		//build by hw add colorDataGrid
		private var sumLine:DataGrid=new DataGrid();
//		private var index:DataGrid=new DataGrid();
//		private var corner:DataGrid=new DataGrid();
		private var buttonBar:HBox=new HBox();;
		
		private var firstBtn:Button=new Button();
		private var prevBtn:Button=new Button();
		private var cb:ComboBox=new ComboBox();
		private var nextBtn:Button=new Button();
		private var lastBtn:Button=new Button();
		private var pageInfo:Label=new Label();
		private var blankBox:Box=new Box();
		private var mainBox:HBox=new HBox();
		private var dataBox:VBox=new VBox();
		private var indexBox:VBox=new VBox();
		
		private var _haveSumLine:Boolean;
		private var _haveButtonBar:Boolean;
		private var _haveIndex:Boolean;
		private var _currentPage:int=1;
		private var _lastPage:int;
		private var _totalSize:int;
		private var _totalPage:int;
		private var _pageSize:int;
		private var sumData:XMLListCollection;
		private var cbData:ArrayCollection=new ArrayCollection();
		//数据控件
		private var proxy:HttpProxy;
		public var ds:EDIDataSource;
		private var _epoParam:EPOParam;
		public var indexCol:DataGridColumn;
		//build by hw add colorDataGrid
		private var _rowColorFunction:Function;
		private var showPageInfoLabel:Label;
		//build by hw add colorDataGrid
		//build by HW 2011-02-28 增加导出功能
		private var _exportCallBackFunction:Function;
		private var fileRef:FileReference;
//		private var fileReference:FileReference;
//		private var xls:Class;
//		private var sheet:Sheet;
//
//		[Bindable]
//		private var fields:Array=new Array();
		//build by HW 2011-02-28 增加导出功能
		/**
		 * 表格控件的构造函数，构造可视化组件，添加事件处理监听
		 * 
		 */		
		public function EDIDataGrid()
		{
			var col:DataGridColumn;
			super();
			this.setStyle("verticalGap","1");
			this.setStyle("borderStyle","solid");
			
//			index.width=40;
//			index.percentHeight=100;
//			indexCol=new DataGridColumn();
//			indexCol.width=40;
//			indexCol.headerText="序号";
//			indexCol.dataField="label";
//			indexCol.sortable=false;
//			index.columns=index.columns.concat(indexCol);
//			
//			index.editable=false;
//			index.headerHeight=30;
//			index.rowHeight=25;
//			//index.verticalScrollPolicy="off";
//			index.setStyle("rollOverColor","#E6E6E6");
//			index.setStyle("alternatingItemColors",["#F7F7F7","#F7F7F7"])
////			index.setStyle("alternatingItemColors",["#E6E6E6","#E6E6E6"])
//			index.setStyle("selectionColor","#F7F7F7");
//			index.setStyle("horizontalGridLines","true");
			
//			corner=new DataGrid();
//			corner.setStyle("horizontalGap","0");
//			corner.width=40;
//			corner.showHeaders=false;
//			corner.height=25;
//			corner.rowHeight=25;
//			corner.rowCount=1;
//			corner.draggableColumns=false;
//			
//			col=new DataGridColumn();
//			col.dataField="col";
//			corner.columns=corner.columns.concat(col);
//			corner.dataProvider=new XMLList(<><row><col>合计</col></row></>);
			
			indexBox.width=0;
			indexBox.percentHeight=100;
			indexBox.setStyle("verticalGap","0");
			indexBox.setStyle("verticalAlign","bottom");
			indexBox.setStyle("horizontalGridLines","true");
			indexBox.setStyle("horizontalGridLineColor","#FFFFFF");
			
//			indexBox.addChild(index);
//			indexBox.addChild(corner);
			
			
			entry.percentWidth=100;
			entry.percentHeight=100;
			entry.draggableColumns=false;
			entry.headerHeight=30;
			entry.rowHeight=25;
			entry.setStyle("useRollOver","false");
			dataBox.addChild(entry);
			
			sumLine.setStyle("horizontalGap","0");
			sumLine.percentWidth=100;
			sumLine.showHeaders=false;
			sumLine.height=25;
			sumLine.rowHeight=25;
			sumLine.rowCount=1;
			sumLine.draggableColumns=false;
			sumLine.setStyle("rollOverColor","#E6E6E6");
			sumLine.setStyle("alternatingItemColors",["#E6E6E6","#eff1f2"])
			sumLine.setStyle("selectionColor","#E6E6E6");
			sumLine.dataProvider=sumData;
			dataBox.addChild(sumLine);
			
			dataBox.percentHeight=100;
			dataBox.percentWidth=100;
			dataBox.setStyle("verticalGap","0");
			
			mainBox.setStyle("horizontalGap","0");
			mainBox.percentHeight=100;
			mainBox.percentWidth=100;
//			mainBox.addChild(indexBox);
			mainBox.addChild(dataBox);
			this.addChild(mainBox);
			
			buttonBar.height=20;
			buttonBar.percentWidth=100;
			buttonBar.setStyle("horizontalAlign","right");
			buttonBar.setStyle("verticalAlign","bottom");
//			buttonBar.setStyle("backgroundColor","white");
			this.addChild(buttonBar);
			
			firstBtn.label="首页";
			buttonBar.addChild(firstBtn);
			prevBtn.label="上一页";
			buttonBar.addChild(prevBtn);
			cb.width=100;
			buttonBar.addChild(cb);
			
			nextBtn.label="下一页";
			buttonBar.addChild(nextBtn);
			lastBtn.label="末页";
			buttonBar.addChild(lastBtn);
			buttonBar.addChild(pageInfo);
			///build by hw
			showPageInfoLabel = new Label();
			showPageInfoLabel.text = "共"+_totalPage+"页 "+_totalSize+"条";
			buttonBar.addChild(showPageInfoLabel);
			///build by hw
			
//			blankBox.setStyle("backgroundColor","black");
//			blankBox.percentHeight=100;
			blankBox.setStyle("backgroundAlpha","0");
			blankBox.percentWidth=100;
			blankBox.height=0;
			this.addChild(blankBox);
			
			firstBtn.addEventListener(MouseEvent.CLICK,firstBtnHandler);
			prevBtn.addEventListener(MouseEvent.CLICK,prevBtnHandler);
			cb.addEventListener(DropdownEvent.CLOSE,cbCloseHandler);
			nextBtn.addEventListener(MouseEvent.CLICK,nextBtnHandler);
			lastBtn.addEventListener(MouseEvent.CLICK,lastBtnHandler);
			
			buttonBar.height=0;
			sumLine.height=0;
			
			entry.addEventListener(ListEvent.CHANGE,changeHandle);
			entry.addEventListener(DataGridEvent.COLUMN_STRETCH,columnStretchHandler);
//			entry.addEventListener(ScrollEvent.SCROLL,scrollHandler);
//			index.addEventListener(ScrollEvent.SCROLL,indexScrollHandler);
		}
		/**
		 * DataGrid中一页显示的记录条数
		 * @param value
		 * 
		 */		
		public function set pageSize(value:int):void
		{
			if(value>0)
			{
				_pageSize=value;
				entry.rowCount=value-1;
				entry.height=(value+2.5)*(entry.rowHeight+1);
				
//				index.rowCount=entry.rowCount;
//				index.rowHeight=entry.rowHeight;
//				index.height=entry.height;
				
				blankBox.percentHeight=100;
				setIndexCount();
			}
			else
			{
				entry.percentHeight=100;
				blankBox.height=0;
			}
		}
		/**
		 * DataGrid中一页显示的记录条数
		 * @return 
		 * 
		 */		
		public function get pageSize():int
		{
			if(_pageSize>0)
				return this._pageSize;
			else
				return 0;
		}
	
		private function setIndexCount(max:int=0):void
		{
			var indexDataProvider:ArrayCollection=new ArrayCollection();
			var i:int;
			var obj:Object;
			if(pageSize>0)
				max=pageSize;
			for(i=1;i<=max;i++)
			{
				obj=new Object();
				obj["label"]=i+(this._currentPage-1)*max;
				indexDataProvider.addItem(obj);
			}
//			index.dataProvider=indexDataProvider;
		}
		/**
		 * 是否显示合计栏
		 * @param value
		 * 
		 */		
		public function set haveSumLine(value:Boolean):void
		{
			this._haveSumLine=value;
			if(value)
			{
				sumLine.height=25;
			}
			else
			{
				sumLine.height=0;
			}
		}
		/**
		 * 是否显示合计栏
		 * @param value
		 * 
		 */	
		public function get haveSumLine():Boolean
		{
			return this._haveSumLine;
		}
		/**
		 * 是否显示翻页按钮
		 * @param value
		 * 
		 */		
		public function set haveButtonBar(value:Boolean):void
		{
			this._haveButtonBar=value;
			if(value)
			{
				buttonBar.height=27;
			}
			else
			{
				buttonBar.height=0;
			}
		}
		/**
		 * 是否显示翻页按钮
		 * @param value
		 * 
		 */
		public function get haveButtonBar():Boolean
		{
			return this._haveButtonBar;
		}
		/**
		 * 是否显示序号
		 * @param value
		 * 
		 */		
		public function set haveIndex(value:Boolean):void
		{
			this._haveIndex=value;
			if(value)
			{
				indexBox.width=40;
			}
			else
			{
				indexBox.width=0;
			}
		}
		/**
		 * 是否显示序号
		 * @param value
		 * 
		 */	
		public function get haveIndex():Boolean
		{
			return this._haveIndex;
		}
		/**
		 * DataGrid双击事件是否有效
		 * @param value
		 * 
		 */		
		override public function set doubleClickEnabled(value:Boolean):void
	    {
	        super.doubleClickEnabled=value;
	        entry.doubleClickEnabled=value;
	    }
		/**
		 * 传递监听函数给内部的DataGrid
		 * @param type
		 * @param listener
		 * @param useCapture
		 * @param priority
		 * @param useWeakReference
		 * 
		 */	    
		override public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void
		{
			if(type==Event.ADDED || type==Event.REMOVED)
				super.addEventListener(type, listener, useCapture, priority, useWeakReference);
			else
				entry.addEventListener(type, listener, useCapture, priority, useWeakReference);
		}
		/**
		 * 设置dataSourceName
		 * @param value
		 * 
		 */		
		public function set dataSourceName(value:String):void
		{
			_dataSourceName=value;
			EDIEventProxy.listenerDataLoad(value,this);
		}
		public function get dataSourceName():String{
			return _dataSourceName;
		}
		/**
		 * 实现IEDIDataLoad接口中的dataLoadHandler方法
		 * @param event
		 *  
		 */		
		public function dataLoadHandler(event:EDIDataEvent):void
		{
			entry.dataProvider=event.value;
			//当数据自动分发的时候
			if(event.value is XMLListCollection || event.value is XMLList)
			{
				var value:Object = event.value;
			
				if(event.value is XMLList)
					value=new XMLListCollection(XMLList(value));
				var rowCount:int=XMLListCollection(value).length;
				setIndexCount(rowCount);
			}
			
//			index.rowCount=entry.rowCount;
//			index.rowHeight=entry.rowHeight;
		}
		private function changeHandle(event:ListEvent):void
		{
			if(this.parentApplication is EDIApplication)
			{
				var ede:EDIDataEvent=new EDIDataEvent(EDIDataEvent.Data_RollingBefore,true); 
				ede.tableName=_dataSourceName;				
				ede.ediTarget=this;
				ede.index=entry.selectedIndex;
				dispatchEvent(ede);
			}
		}
		//
		private function clone( source:Object ):*
		{
		    var myBA:ByteArray = new ByteArray();
		    myBA.writeObject( source );
		    myBA.position = 0;
		    return( myBA.readObject() );
		}
		
		 override public function initialize():void{
		 	super.initialize();
		 	this.columns = entry.columns;
		 }
		 
		
		/**
		 * EDIDataGrid列集合
		 * @param value
		 * 
		 */		
		public function set columns (value:Array):void
		{
			var i:int;
			var dataField:String;
			var staticValue:String;
			var cols:EDIDataGridColumn;
			var sumColumns:Array;
			
			var indexCol:EDIDataGridColumn=new EDIDataGridColumn();
			indexCol.width=40;
			indexCol.headerText="序号";
			indexCol.sortable=false;
			indexCol.draggable  =false;
			indexCol.itemRenderer = new ClassFactory(IndexLabelItemRender);
//			index.columns=index.columns.concat(indexCol);
//			value.unshift(indexCol);
			if(_haveIndex==true){
				if(entry.columns.length>0){
					if((entry.columns[0] as EDIDataGridColumn).headerText!="序号"){
						value.unshift(indexCol);
					}
				}
				
			}
			entry.columns=value.concat();
				
			
//			sumColumns=new Array();
//			for(i=0;i<entry.columns.length;i++)
//			{
//				col=new EDIDataGridColumn();
//				col.minWidth=0;
//				col.dataField=EDIDataGridColumn(entry.columns[i]).dataField;
//				col.width=EDIDataGridColumn(entry.columns[i]).width;
//				col.visible=EDIDataGridColumn(entry.columns[i]).visible;
//				sumColumns.push(col);
//			}
//			sumLine.columns=sumColumns.concat();
			
			sumColumns=new Array();
			if(haveSumLine){
				var totalLabelColumn:EDIDataGridColumn = new EDIDataGridColumn();
				totalLabelColumn.dataField = "col";
				totalLabelColumn.width=(entry.columns[0] as EDIDataGridColumn).width;
				sumColumns.push(totalLabelColumn);
			}
			
			
			for(i=1;i<entry.columns.length;i++)
			{
				if(entry.columns[i] is CheckBoxColumn)
				{
					cols=new EDIDataGridColumn();
					cols.minWidth=0;
					cols.dataField=CheckBoxColumn(entry.columns[i]).dataField;
					cols.width=CheckBoxColumn(entry.columns[i]).width;
					cols.visible=CheckBoxColumn(entry.columns[i]).visible;
				}
				else
				{
										
					cols=(BOPObjectUtils.clone(entry.columns[i]) as EDIDataGridColumn);
					//完成对象的深度复制
					 	var qClassName:String = getQualifiedClassName(entry.columns[i]);
                        var objectType:Class = getDefinitionByName(qClassName) as Class;
                        registerClassAlias(qClassName, objectType);
                        var copier : ByteArray = new ByteArray();
                        copier.writeObject(entry.columns[i]);
                        copier.position = 0;
                     cols  = copier.readObject() as EDIDataGridColumn;
                     //完成对象的深度复制   
					if((cols as EDIDataGridColumn).itemRenderer!=null){
						cols.itemRenderer = null;
					}
				}
				sumColumns.push(cols);
			}
			sumLine.columns=sumColumns.concat();			
			
			sumData=new XMLListCollection(new XMLList(<data><row><col>合计</col></row></data>));
			
			for(i=0;i<value.length;i++)
			{
				if(value[i] is EDIDataGridColumn)
				{
					dataField=EDIDataGridColumn(value[i]).dataField;
					staticValue=EDIDataGridColumn(value[i]).staticString;
					if(!staticValue)
						staticValue="";
					XML(sumData.children()[0]).appendChild( new XML(<{dataField} sumValue="0">{staticValue}</{dataField}>));
				}
			}
			sumLine.dataProvider=sumData.children()[0];
			
//			index.headerHeight=entry.headerHeight;
		}
		/**
		 * EDIDataGrid列集合
		 * @param value
		 * 
		 */	
		public function get columns():Array
		{
			return entry.columns;
		}
		
		/**
		 * EDIDataGrid的数据源
		 * @return 
		 * 
		 */		
		public function get dataProvider():Object
		{
			return entry.dataProvider;
		}
		/**
		 * EDIDataGrid的数据源
		 * @param value，XMLListCollection格式
		 * 
		 */		
		public function set dataProvider(value:Object):void
		{
			var i:int;
			var j:int;
			var rowObj:Object;
			var dataObj:Object;
			var dataField:String;
			var col:EDIDataGridColumn;
			var num:Number;
			var rowData:XML;
			var rowCount:int;
			var numformatter:NumberFormatter;
			var cellData:String;
			this.columns = entry.columns;
			if(value is XMLListCollection || value is XMLList)
			{
				if(value is XMLList)
					value=new XMLListCollection(XMLList(value));
				rowCount=XMLListCollection(value).length;
				for(i=0;i<rowCount;i++)
				{
					rowData=XML((value as XMLListCollection).getItemAt(i));				
					for(j=0;j<entry.columns.length;j++)
					{
						col=(entry.columns[j] as EDIDataGridColumn);

						if(col)
						{
							numformatter=col.numformatter;
							dataField=col.dataField;					
							if(col.sumType=="sum" || col.sumType=="average")
							{
								if(i==0)
									num=0;
								else
									num=Number(XML(XML(sumData.getItemAt(0)).row[0])[dataField].@sumValue);
								//如果设定了小数位格式
								if(numformatter.precision>=0)
								{
									cellData=numformatter.format(rowData[dataField]);
									rowData[dataField]=cellData;
								}
								else
								{
									cellData=rowData[dataField];
								}
								num+=Number(cellData);
								XML(XML(sumData.getItemAt(0)).row[0])[dataField].@sumValue=num.toString();
								//如果是最后一条记录
								var numStr:String;
								if(i==XMLList(value).length()-1)
								{
									if(col.sumType=="average")
									{
										num=num/rowCount;
										
									}	
									numStr=num.toString();
									if(numformatter.precision>=0)
									{
										numStr=numformatter.format(num);
									}
									XML(XML(sumData.getItemAt(0)).row[0])[dataField]=numStr;
								}
							}
							if(col.sumType=="count")
							{
								//如果是最后一条记录
								if(i==XMLList(value).length()-1)
								{
									XML(XML(sumData.getItemAt(0)).row[0])[dataField]=rowCount;
								}
							}
						}
					}
				}
			}
//			var a:String = XMLList(value).toString();
//			var b:String  = 
//			value  = XMLList((XMLList(value).toString())+(XML(sumData.getItemAt(0)).row[0]).toString());
//			Alert.show("数据源value: "+value.toString());
			entry.dataProvider=value;
			//如果pageSize==0，没有地方给序号赋最大值，要在这里指定一下
			if(pageSize==0)
				setIndexCount(rowCount);

//			index.rowCount=entry.rowCount;
//			index.rowHeight=entry.rowHeight;
		}
		/**
		 * 表格调整列宽的事件处理函数
		 * @param event
		 * 
		 */
		protected function columnStretchHandler(event:DataGridEvent):void
		{
			var col:int=event.columnIndex;
			DataGridColumn(sumLine.columns[col]).width=DataGridColumn(entry.columns[col]).width;
		}
		/**
		 * 构建epoParam，并向服务器索取数据
		 * @param currentPage 
		 * 
		 */		
		public function bulidAndSendSql(currentPage:int=-1):void
		{
			if(!this.dataSourceName)
				this.dataSourceName="entry";
			if(epoParam)
			{
				//如果是从页面初始化中传递进来的
				if(currentPage!=this._currentPage && currentPage!=-1)
				{
					this._currentPage=currentPage;
					setIndexCount();
				}
				EDIApplication.outputDebug("appName: "+EDIApplication.appName);
				this.ds=EDIApplication(this.parentApplication).ds;
				proxy=new HttpProxy(EDIApplication.appName,true,this.ds);
				proxy.url=EDIApplication.path+EDIApplication.appName+".app";
				//?ediSessionId="+EDIApplication.sessionId;
				epoParam.dsName=this.dataSourceName;
				epoParam.currentPage=_currentPage;
				epoParam.pageSize=pageSize;
				epoParam.totalSize=_totalSize;
				
				proxy.addPoParam(epoParam);
				proxy.resultCallback=getEqlDataHandeler;
				proxy.send();
			}
		}
		/**
		 * 合计栏设置样式
		 * @param styleProp 属性名
		 * @param newValue 属性值
		 * 
		 */		
		public function sumLineSetStyle(styleProp:String, newValue:*):void
    	{
    		if(sumLine)
    			sumLine.setStyle(styleProp,newValue);
    	}
    	/**
    	 * 对数据表格设置属性
    	 * @param styleProp 属性名
    	 * @param newValue 属性值
    	 * 
    	 */    	
    	public function entrySetStyle(styleProp:String, newValue:*):void
    	{
			if(entry)    		
    			sumLine.setStyle(styleProp,newValue);
    	}
		//请求数据返回处理
		private function getEqlDataHandeler(event:HttpProxyResult):void
		{
			var i:int;
			var rowXml:XML;
			var obj:Object;
			var xml:XML;
			if(event.poNext())
			{
				if(event.currentPoResult.dsName==dataSourceName)
				{
					rowXml=new XML(event.getPoResultByDsName(dataSourceName).table.toXMLString());
					xml=new XML(event.getPoResultByDsName(dataSourceName).xml.toXMLString());
					this._totalSize=Number(xml.totalSize);
					this.totalPage=Number(xml.totalPage);
					showPageInfoLabel.text = "共"+_totalPage+"页 "+_totalSize+"条";
					if(this._totalPage>1)
					{
						cbData.removeAll();
						for(i=1;i<=_totalPage;i++)
						{
							obj=new Object();
							obj["label"]=i.toString();
//							+"/"+_totalPage;
							obj["data"]=i;
							cbData.addItem(obj);
						}
						
						cb.dataProvider=cbData;
						cb.selectedIndex=this._currentPage-1;
						
						firstBtn.enabled=true;
					}
					else
					{
						firstBtn.enabled=true;
					}
					this._lastPage=this._currentPage;
					
					if(rowXml.children().length()>0)
						dataProvider=rowXml.children();
					else
						dataProvider=null;
				}
			}
		}
		
		private function firstBtnHandler(event:MouseEvent):void
		{
			if(this._currentPage>1)
			{
				bulidAndSendSql(1);
			}
		}
		private function prevBtnHandler(event:MouseEvent):void
		{
			if(this._currentPage>1)
			{
				bulidAndSendSql(_currentPage-1);
			}
		}
		private function cbCloseHandler(event:DropdownEvent):void
		{
			if(cb.selectedItem)
			{
				if(this._currentPage!=int(cb.selectedItem.data))
				{
					bulidAndSendSql(cb.selectedItem.data);
				}
			}
		}
		private function nextBtnHandler(event:MouseEvent):void
		{
			if(this._currentPage < this._totalPage)
			{
				bulidAndSendSql(this._currentPage+1);
			}
		}
		private function lastBtnHandler(event:MouseEvent):void
		{
			if(this._currentPage < this._totalPage)
			{
				bulidAndSendSql(this._totalPage);
			}
		}
		/**
		 * 记录总数，从服务器段取得，发回服务器端，避免服务器每次进行运算
		 * @param value
		 * 
		 */		
		public function set totalSize(value:int):void
		{
			this._totalSize=value;
		}
		
		public function set totalPage(value:int):void
		{
			var i:int;
			var obj:Object;
			this._totalPage=value;
			cbData.removeAll();
			for(i=1;i<=_totalPage;i++)
			{
				obj=new Object();
				obj["label"]=i.toString();
//				+"/"+_totalPage;
				obj["data"]=i;
				cbData.addItem(obj);
			}
			cb.dataProvider=cbData;
			cb.selectedIndex=this._currentPage-1;
		}
//		private function scrollHandler(event:ScrollEvent):void
//		{
////			index.verticalScrollPosition=event.position;
//		}
		private function indexScrollHandler(event:ScrollEvent):void{
			entry.verticalScrollPosition = event.position;
		}
		public function get currentPage():int
		{
			return this._currentPage;
		}
		public function set currentPage(value:int):void
		{
			this._currentPage=value;
		}
		public function set epoParam(value:EPOParam):void
		{
			this._epoParam=value;
			currentPage=1;
			totalSize=0;
		}
		public function get epoParam():EPOParam
		{
			return _epoParam;
		}
		//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 传递DataGrid本身的属性
		 * @param item
		 */
		 
		public function addDataEffectItem(item:Object):void
	    {
	    	entry.addDataEffectItem(item);
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */		
		public function set allowMultipleSelection(value:Boolean):void
	    {
	        entry.allowMultipleSelection=value;
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */	    
		public function get allowMultipleSelection():Boolean
	    {
	        return entry.allowMultipleSelection;
	    }
		/**
		 * 只读属性,canvas本身也有这个属性
		 * @return 
		 * 
		 */	    
		override public function get baselinePosition():Number
		{
			return entry.baselinePosition;
		}
		/**
		 * 只读属性，传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get columnCount():int
		{
			return entry.columnCount;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @param event
		 * @return 
		 * 
		 */		
		public function calculateDropIndex(event:DragEvent = null):int
	    {
	    	return entry.calculateDropIndex(event);
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param colIndex
	     * @param rowIndex
	     * 
	     */	    
	    public function createItemEditor(colIndex:int, rowIndex:int):void
	    {
	    	entry.createItemEditor(colIndex, rowIndex);
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		override public function get data():Object
	    {
	        return entry.data;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param value
	     * 
	     */		
	    override public function set data(value:Object):void
	    {
	    	entry.data=value;
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */	    
		public function set dragEnabled(value:Boolean):void
		{
			entry.dragEnabled=value;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get dragEnabled():Boolean
		{
			return entry.dragEnabled;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */		
		public function set dragMoveEnabled(value:Boolean):void
		{
			entry.dragMoveEnabled=value;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get dragMoveEnabled():Boolean
		{
			return entry.dragMoveEnabled;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */	    
		//读写属性
		public function set draggableColumns(value:Boolean):void
	    {
	        entry.draggableColumns = value;
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */	    
		public function get draggableColumns():Boolean
	    {
	        return entry.draggableColumns;
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */	    
		public function set dropEnable(value:Boolean):void
		{
			entry.dropEnabled=value;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get dropEnable():Boolean
		{
			return entry.dropEnabled;
		}
		
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */	    
		public function set editable(value:Boolean):void
		{
			entry.editable=value;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get editable():Boolean
		{
			return entry.editable;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */		
		public function set editedItemPosition(value:Object):void
		{
			entry.editedItemPosition=value;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get editedItemPosition():Object
		{
			return entry.editedItemPosition;
		}
		
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get editedItemRenderer():IListItemRenderer
		{
			return entry.editedItemRenderer;
		}

		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */		
		override public function set enabled(value:Boolean):void
    	{
			if(entry)
				entry.enabled=value;
			super.enabled=value;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		override public function get enabled():Boolean
		{
			return super.enabled;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @param str
		 * @return 
		 * 
		 */		
		public function findString(str:String):Boolean
	    {
	    	return entry.findString(str);
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get fontContext():IFlexModuleFactory
	    {
	        return entry.moduleFactory;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param moduleFactory
	     * 
	     */	    
	    public function set fontContext(moduleFactory:IFlexModuleFactory):void
	    {
	        entry..moduleFactory = moduleFactory;
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */	    
		override public function set focusPane(value:Sprite):void
	    {
	    	entry.focusPane=value;
	    }
    	/**
    	 * 传递DataGrid本身的属性
    	 * @param target
    	 * @param semanticProperty
    	 * @return 
    	 * 
    	 */	    
    	public function getRendererSemanticValue(target:Object,semanticProperty:String):Object
	    {
	        return entry.getRendererSemanticValue(target,semanticProperty); 
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */	    
		public function set headerHeight(value:Number):void
		{
			entry.headerHeight=value;
//			index.headerHeight=value;
		}
		public function get headerHeight():Number
		{
			return entry.headerHeight;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */		
		override public function set horizontalScrollPosition(value:Number):void
    	{
    		super.horizontalScrollPosition=value;
    		entry.horizontalScrollPosition=value;
    	}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */    	
		override public function get horizontalScrollPosition():Number
		{
			return entry.horizontalScrollPosition;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @param event
		 * 
		 */		
		public function hideDropFeedback(event:DragEvent):void
	    {
	    	entry.hideDropFeedback(event);
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param index
	     * @return 
	     * 
	     */	    
	    public function indexToItemRenderer(index:int):IListItemRenderer
	    {
	    	return entry.indexToItemRenderer(index);
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param itemRenderer
	     * @return 
	     * 
	     */	    
	    public function itemRendererToIndex(itemRenderer:IListItemRenderer):int
	    {
	    	return entry.itemRendererToIndex(itemRenderer);
	    }
		
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */
		public function set itemEditorInstance(value:IListItemRenderer):void
		{
			entry.itemEditorInstance=value;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get itemEditorInstance():IListItemRenderer
		{
			return entry.itemEditorInstance;
		}
		
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */
		public function set imeMode(value:String):void
		{
		    entry.imeMode = value;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get imeMode():String
		{
		    return entry.imeMode;
		}
		
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */		
		public function set itemRenderer(value:IFactory):void
		{
		    entry.itemRenderer = value;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get itemRenderer():IFactory
	    {
	    	return entry.itemRenderer;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param data
	     * @return 
	     * 
	     */	    
	    public function isItemEditable(data:Object):Boolean
	    {
	    	return entry.isItemEditable(data);
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @param data
		 * @return 
		 * 
		 */	    
		public function itemToLabel(data:Object):String
	    {
	        return entry.itemToLabel(data);
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param rowIndex
	     * @param colIndex
	     * @return 
	     * 
	     */	    
	    public function indicesToIndex(rowIndex:int, colIndex:int):int
	    {
	        return entry.indicesToIndex(rowIndex,colIndex);
	    }
		/**
		 * 传递DataGrid本身的属性，执行EDIDataGrid的invalidateDisplayList同时执行entry的invalidateDisplayList
		 * 
		 */		
		override public function invalidateDisplayList():void
    	{
    		super.invalidateDisplayList();
    	}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get lockedColumnCount():int
	    {
	        return entry.lockedColumnCount;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param value
	     * 
	     */	    
	    public function set lockedColumnCount(value:int):void
	    {
	        entry.lockedColumnCount=value;
	    }
	    
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */	    
		public function get lockedRowCount():int
	    {
	        return entry.lockedRowCount;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param value
	     * 
	     */	    
	    public function set lockedRowCount(value:int):void
	    {
	        entry.lockedRowCount=value;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @return 
	     * 
	     */	    
	    public function get labelField():String
	    {
	        return entry.labelField;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param value
	     * 
	     */
	    public function set labelField(value:String):void
	    {
	    	entry.labelField=value;
	 	}
	 	/**
	 	 * 传递DataGrid本身的属性
	 	 * @return 
	 	 * 
	 	 */	 	
	 	public function get labelFunction():Function
	    {
	        return entry.labelFunction;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param value
	     * 
	     */	    
	    public function set labelFunction(value:Function):void
	    {
	    	entry.labelFunction=value
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @return 
	     * 
	     */	    
	    public function get listData():BaseListData
	    {
	        return entry.listData;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param value
	     * 
	     */	    
	    public function set listData(value:BaseListData):void
	    {
	        entry.listData = value;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param value
	     * 
	     */		
	    public function set minColumnWidth(value:Number):void
	    {
	    	entry.minColumnWidth=value;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @return 
	     * 
	     */	    
	    public function get minColumnWidth():Number
	    {
	        return entry.minColumnWidth;
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @param index
		 * @param count
		 * @return 
		 * 
		 */	    
		public function measureWidthOfItems(index:int = -1, count:int = 0):Number
		{
			return entry.measureWidthOfItems(index,count);
		}
		/**
		 * 传递DataGrid本身的属性
		 * @param index
		 * @param count
		 * @return 
		 * 
		 */		
		public function measureHeightOfItems(index:int = -1, count:int = 0):Number
		{
			return entry.measureHeightOfItems(index,count);
		}
	    /**
	     * 传递DataGrid本身的属性
	     * @return 
	     * 
	     */	    
	    public function get nullItemRenderer():IFactory
	    {
	        return entry.nullItemRenderer;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param value
	     * 
	     */	    
	    public function set nullItemRenderer(value:IFactory):void
	    {
	    	entry.nullItemRenderer=value;
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get offscreenExtraRowsOrColumns():int
	    {
	        return entry.offscreenExtraRowsOrColumns;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param value
	     * 
	     */	    
	    public function set offscreenExtraRowsOrColumns(value:int):void
	    {
	    	entry.offscreenExtraRowsOrColumns=value;
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */		
		public function set resizableColumns(value:Boolean):void
		{
			entry.resizableColumns=value;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get resizableColumns():Boolean
		{
			return entry.resizableColumns;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get rowHeight():Number
	    {
	        return entry.rowHeight;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param value
	     * 
	     */	    
	    public function set rowHeight(value:Number):void
	    {
	    	entry.rowHeight=value;
//	    	index.rowHeight=value;
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */	    
		public function set rowCount(value:int):void
		{
			entry.rowCount=value;
//			index.rowCount=value;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get rowCount():int
		{
			return entry.rowCount;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @param item
		 * 
		 */		
		public function removeDataEffectItem(item:Object):void
	    {
	    	entry.removeDataEffectItem(item);
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param index
	     * @return 
	     * 
	     */	    
	    public function scrollToIndex(index:int):Boolean
		{
			return entry.scrollToIndex(index);
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get showHeaders():Boolean
	    {
	        return entry.showHeaders;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param value
	     * 
	     */	    
	    public function set showHeaders(value:Boolean):void
	    {
	    	entry.showHeaders=value;
//	    	index.showHeaders=value;
	    }

	    /**
	     * 传递DataGrid本身的属性
	     * @return 
	     * 
	     */		
	    public function get selectable():Boolean
	    {
	        return entry.selectable;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param value
	     * 
	     */	    
	    public function set selectable(value:Boolean):void
	    {
	        entry.selectable = value;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @return 
	     * 
	     */	    
	    public function get selectedIndex():int
	    {
	        return entry.selectedIndex;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param value
	     * 
	     */	    
	    public function set selectedIndex(value:int):void
	    {
	    	entry.selectedIndex=value;
	    }
		
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */		
		public function set selectedItem(value:Object):void
		{
			entry.selectedItem=value;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get selectedItem():Object
		{
			return entry.selectedItem;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get selectedItems():Array
	    {
	        return entry.selectedItems;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param items
	     * 
	     */	    
	    public function set selectedItems(items:Array):void
	    {
	    	entry.selectedItems=items;
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get selectedIndices():Array
	    {
	        return entry.selectedIndices;
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @param indices
	     * 
	     */	    
	    public function set selectedIndices(indices:Array):void
	    {
	    	entry.selectedIndices=indices;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @param event
		 * 
		 */     	
		public function showDropFeedback(event:DragEvent):void
	    {
	    	entry.showDropFeedback(event);
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */	    
		public function set sortableColumns(value:Boolean):void
		{
			entry.sortableColumns=value;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get sortableColumns():Boolean
		{
			return entry.sortableColumns;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */		
		override public function set showInAutomationHierarchy(value:Boolean):void
	    {
//	        entry.showInAutomationHierarchy(value);
	        //do not allow value changes
	    }
	    /**
	     * 传递DataGrid本身的属性
	     * @return 
	     * 
	     */	    
	    public function get value():Object
	    {
	    	return entry.value;
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */		
		public function get variableRowHeight():Boolean
	    {
	        return entry.variableRowHeight;
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */	    
		public function set variableRowHeight(value:Boolean):void
	    {
	    	entry.variableRowHeight=value;
	    }
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */	    
		override public function set verticalScrollPosition(value:Number):void
    	{
    		entry.verticalScrollPosition=value;
    	}
		/**
		 * 传递DataGrid本身的属性
		 * @return 
		 * 
		 */    	
		override public function get verticalScrollPosition():Number
		{
			return entry.verticalScrollPosition;
		}
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */		
		public function set verticalGridLines(value:String):void
		{
			entry.setStyle("verticalGridLines",value);
		}
		/**
		 * 传递DataGrid本身的属性
		 * @param value
		 * 
		 */		
		public function set alternatingItemColors(value:Array):void
		{
			entry.setStyle("alternatingItemColors",value);
		}
		//build by hw add colorDataGrid
		public function set rowColorFunction(f:Function):void
		{
			entry.rowColorFunction=f;
		}

		public function get rowColorFunction():Function
		{
			return entry.rowColorFunction;
		}
		//build by hw add colorDataGrid
		//build by HW 2011-02-28 增加导出功能
		public function set exportCallBackFunction(f:Function):void{
			this._exportCallBackFunction = f;
		}
		public function get exportCallBackFunction():Function{
			return this._exportCallBackFunction;
		}
		/**
		 * DataGrid的导出功能,该功能共需要四个参数,见参数说明. 
		 * @param fileName   导出的文档名称
		 * @param sheetname  导出的excel的标签名称
		 * @param title      导出的excel的标题
		 * @param serverPath 导出的文件在服务器上存放的路径,默认为UserFiles下.可自定义,如"UserFiles\\File\\file",但需要保证该路径在服务器上真实存在.
		 * 
		 */		
		public function buildExcelByData(fileName:String,sheetname:String,title:String,serverPath:String="UserFiles"):void{
			var array:Array = entry.columns;
			var headTextXmllist:XML = new XML(<row></row>);
			EDIApplication.outputDebug("headTextXmllist: "+headTextXmllist.toString());
			for(var i:int=0;i<array.length;i++){
				var dc:EDIDataGridColumn = array[i] as EDIDataGridColumn;
				headTextXmllist[dc.dataField] = dc.headerText;
			}
			var dataxmllist:XMLList = XMLList(entry.dataProvider);
			var str:String ="<table filename='"+fileName+"' sheetname='"+sheetname+"' title='"+title+"'>"+ headTextXmllist.toString()+dataxmllist.toString()+"</table>";
			
			exportExcel(fileName,str,serverPath);
		}
		private function exportExcel(fileName:String,str:String,serverPath:String){
			EDIApplication.outputDebug("开始执行服务.....");
			var spo:SPOParam = new SPOParam();
			spo.serviceName = "ServicesExportExcelForDataGrid.serviceExportExcel";
			var s1 = BOPStringUtils.replace(str,"<![CDATA[",">");
			var s2 = BOPStringUtils.replace(s1,"]]>","");	
				
			spo.addParameters("dataInfo",s2);
			spo.addParameters("serverpath",serverPath);
			spo.dsName = "exportdatainfos_hrsoft";
			var hp:HttpProxy = new HttpProxy(EDIApplication.appName);
			hp.addPoParam(spo);
			hp.send();
			EDIApplication.outputDebug("发送服务.....");
			hp.resultCallback = function(e:HttpProxyResult):void{
				EDIApplication.outputDebug("开始执行回调.....");
				var result:String = e.getPoResultByDsName("exportdatainfos_hrsoft").object.String;
				Alert.yesLabel = "确定";
				Alert.cancelLabel = "取消";
				EDIAlert.show("导出成功,是否下载?","温馨提示",Alert.YES|Alert.CANCEL,null,function(ce:mx.events.CloseEvent):void{
					if(ce.detail == Alert.YES){
						download(fileName,result,serverPath);
					}
				},null,Alert.YES);
				
			};
		}
		
		
		private function download(downFileName:String,serverFileName:String,serverPath:String):void{
			var filename:String;
			var fileurl:String = EDIApplication.path + serverPath+"/"+serverFileName+".xls";
			EDIApplication.outputDebug("fileurl: "+fileurl); 
			var filename:String =  downFileName;
			fileRef = new FileReference();
			fileRef.addEventListener(Event.COMPLETE,completeHandler);
			fileRef.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);
			EDIApplication.outputDebug("URLRequest: "+new URLRequest(fileurl).data +" : "+new URLRequest(fileurl).url);		
			fileRef.download(new URLRequest(fileurl),filename);
//			new OpenWindow(fileurl);
		}

		private function completeHandler(e:Event):void{	
			EDIAlert.show("下载成功！","温馨提示");
		}

		private function errorHandler(e:Event):void{	
			EDIAlert.show("下载失败！请检查网络连接重试！","温馨提示");
		}
		
		//以下为通过sql语句导出excel文件
		public function buildExcelBySql(sqlinfo:String,fileName:String,sheetname:String,title:String,serverPath:String="UserFiles"):void{
			var array:Array = entry.columns;
			var headArray:Array = new Array();
			var headTextXmllist:XML = new XML(<row></row>);
			EDIApplication.outputDebug("headTextXmllist: "+headTextXmllist.toString());
			for(var i:int=0;i<array.length;i++){
				var dc:EDIDataGridColumn = array[i] as EDIDataGridColumn;
				headArray.push(dc.dataField+":"+dc.headerText);
				EDIApplication.outputDebug("dc.headerText: "+dc.headerText);
			}
			exportExcelBySql(sqlinfo,headArray.join(";"),fileName,serverPath,title,sheetname);
		}
		//以下为通过sql语句导出excel文件调用服务方法
		private function exportExcelBySql(sqlinfo:String,headText:String,fileName:String,serverPath:String,title:String,sheetname:String){
			EDIApplication.outputDebug("开始执行服务.....");
			var spo:SPOParam = new SPOParam();
			spo.serviceName = "ServicesExportExcelForDataGrid.serviceExportExcelBySql";
			spo.addParameters("sqlinfo",sqlinfo);
			spo.addParameters("headText",headText);
			spo.addParameters("appname",EDIApplication.appName);
			spo.addParameters("serverpath",serverPath);
			spo.addParameters("sheetname",sheetname);
			spo.addParameters("title",title);
			spo.dsName = "exportdatainfos_hrsoft_sql";
			var hp:HttpProxy = new HttpProxy(EDIApplication.appName);
			hp.addPoParam(spo);
			hp.send();
			EDIApplication.outputDebug("发送服务.....");
			hp.resultCallback = function(e:HttpProxyResult):void{
				EDIApplication.outputDebug("开始执行回调.....");
				var result:String = e.getPoResultByDsName("exportdatainfos_hrsoft_sql").object.String;
				Alert.yesLabel = "确定";
				Alert.cancelLabel = "取消";
				EDIAlert.show("导出成功,是否下载?","温馨提示",Alert.YES|Alert.CANCEL,null,function(ce:mx.events.CloseEvent):void{
					if(ce.detail == Alert.YES){
						download(fileName,result,serverPath);
					}
				},null,Alert.YES);
				
			};
		}	
//		public function exportToExcel(fileName:String,titleName:String,sheetName:String):void{
//			sheet=new Sheet();
//			var dataProviderCollection:ArrayCollection =new ArrayCollection();
//			var datas:ListCollectionView = this.dataProvider as ListCollectionView;
//			if(!datas){
//				return;
//			}
//			for(var k:int=0;k<datas.length;k++){
//				var x:XML = datas.getItemAt(k) as XML;
//				var obj:Object = new Object();
//				for(var m:int=0;m<x.children().length();m++){
//					var name:String = x.children()[m].name();
//					var value:String = x[name];
//					obj[name] = value;
//				}
//		
//				dataProviderCollection.addItem(obj);
//			}
//			var rowCount:int=dataProviderCollection.length;
//			sheet.resize(rowCount + 1, this.columnCount);
//			sheet.header = titleName;
//			sheet.setCell(0,5,sheetName);
//			var columns:Array=this.columns;
//			var i:int=0;
//	for each (var field:DataGridColumn in columns)
//	{
//		fields.push(field.dataField.toString());
//		
//		sheet.setCell(2, i, field.headerText.toString());
//		i++;
//	}
//
//	for (var r:int=0; r < rowCount; r++)
//	{
//		var record:Object=dataProviderCollection.getItemAt(r);
//		insertRecordInSheet(r + 3, sheet, record);
//	}
//	try{
//	var xls:ExcelFile=new ExcelFile();
//	xls.sheets.addItem(sheet);
//
//	var bytes:ByteArray=xls.saveToByteArray();
//	var fr:FileReference=new FileReference();
//	fr.addEventListener(Event.COMPLETE,saveok);
//	fr.save(bytes, fileName+".xls");
//	}catch(e:Error){
//			EDIAlert.show("请使用flash player 10或以上版本进行导出！","温馨提示");
//		}
//		}
//private function saveok(e:Event):void{
//	EDIAlert.show("导出成功！","温馨提示");
//}
//private function insertRecordInSheet(row:int, sheet:Sheet, record:Object):void
//{
//	var colCount:int=this.columnCount;
//	for (var c:int; c < colCount; c++)
//	{
//		var i:int=0;
//		for each (var field:String in fields)
//		{
//			for each (var value:String in record)
//			{
//				if (record[field].toString() == value)
//					sheet.setCell(row, i, value);
//			}
//			i++;
//		}
//	}
//}
		//build by HW 2011-02-28 增加导出功能
	}
}